package com.allwees.bs.module.oms.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.allwees.bs.core.modelbase.branch.EBranchType;
import com.allwees.core.common.constant.EWithdrawAccountType;
import com.allwees.core.common.util.MoneyUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.experimental.Accessors;

import javax.persistence.Column;
import java.math.BigDecimal;

@Data
@ToString
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = true)
@TableName("fms_merchant_account")
public class FmsMerchantAccount extends FmsBaseAccount {
    private EBranchType branchType;

    /**
     * 已结算金额
     */
    @Column(precision = 8, scale = 2)
    private BigDecimal settledAmount = BigDecimal.ZERO ;


    private Integer accountType;

    public  String getAccountTypeDesc(){
        return  EWithdrawAccountType.getDescByAccountType(accountType);
    }


    /**
     * 提现中金额
     */
    @Column(precision = 8, scale = 2)
    private BigDecimal withdrawingAmount  = BigDecimal.ZERO;

    /**
     * 已提现金额
     */
    @Column(precision = 8, scale = 2)
    private BigDecimal withdrawedAmount  = BigDecimal.ZERO;

    /**
     * 在途金额
     */
    @Column(precision = 8, scale = 2)
    private BigDecimal  inShippingAmt  = BigDecimal.ZERO;


    /**
     * 待结算金额
     */
    @Column(precision = 8, scale = 2)
    private BigDecimal  unsettleShippingAmt  = BigDecimal.ZERO;


    /**
     * 待发总金额
     */
    @Column(precision = 8, scale = 2)
    private BigDecimal  waitingShipAmt  = BigDecimal.ZERO;

    /**
     * 退款总金额
     */
    @Column(precision = 8, scale = 2)
    private BigDecimal  refundAmt  = BigDecimal.ZERO;

    /**
     * 银行卡数
     */
    @Column
    private Integer bankNum;


    /**
     * 账户名
     */
    private  String accountName;



    public  void doPlatformRefundAmt( AccountTransit accountTransit) {
        refundAmt =  MoneyUtil.add(refundAmt,accountTransit.getAmount());
        waitingShipAmt =  MoneyUtil.sub(waitingShipAmt,accountTransit.getAmount());
    }

    public  void doRetailerRefundAmt( AccountTransit accountTransit) {
        refundAmt =  MoneyUtil.add(refundAmt,accountTransit.getAmount());
        waitingShipAmt =  MoneyUtil.sub(waitingShipAmt,accountTransit.getAmount());
    }


    public  void doRefundAmtWaitShip( AccountTransit accountTransit) {
        refundAmt =  MoneyUtil.add(refundAmt,accountTransit.getAmount());
        waitingShipAmt =  MoneyUtil.sub(waitingShipAmt,accountTransit.getAmount());
    }

    public  void doRefundAmtShipped( AccountTransit accountTransit) {
        refundAmt =  MoneyUtil.add(refundAmt,accountTransit.getAmount());
        unsettleShippingAmt = MoneyUtil.sub(unsettleShippingAmt,accountTransit.getAmount());
    }

    public  void calculateWaitingShipAmt(AccountTransit accountTransit ) {
        waitingShipAmt =  MoneyUtil.add(waitingShipAmt,accountTransit.getAmount());//待发总金额
    }

    public  void calculateInShippingAmt( AccountTransit accountTransit){
        waitingShipAmt =  MoneyUtil.sub(waitingShipAmt,accountTransit.getAmount());//待发总金额
        inShippingAmt =  MoneyUtil.add(inShippingAmt,accountTransit.getAmount());//发货后的在途总金额
    }

    /**
     * 按未结算单计算未结算金额
     *
     * @param accountTransit
     */
    public void calculateUnSettle(  AccountTransit accountTransit) {
        inShippingAmt =  MoneyUtil.sub(inShippingAmt,accountTransit.getAmount());//发货后的在途总金额
        unsettleShippingAmt = MoneyUtil.add(unsettleShippingAmt, accountTransit.getAmount());
    }

    public void calculateSettle( AccountTransit accountTransit) {
        settledAmount = MoneyUtil.add(settledAmount, accountTransit.getAmount());
        unsettleShippingAmt = MoneyUtil.sub(unsettleShippingAmt,accountTransit.getAmount());
        balance = MoneyUtil.add(balance, accountTransit.getAmount());
    }

}
